// import VueRouter from "vue-router";
import { createRouter, createWebHashHistory } from 'vue-router'
import store from '@/store/index.js'
const Home = () => import("../components/Home")
// const Listview = () => import("../views/Listview")
const Searchpage = () => import("../views/SearchPage")
const Login = () => import("../components/Login")
const LoMin = () => import("../components/LoMe")

// const UserMusic = () => import("../components/UserMusic")
// const About = () => import("../components/About")
// const LoMe = () => import("../components/LoMe")
// const Sonelist = () => import("../components/Sonelist")

//重定向的问题
// const originalPush = VueRouter.prototype.push

// VueRouter.prototype.push = function push(location, onResolve, onReject) {

//     if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)

//     return originalPush.call(this, location).catch(err => err)

// }
// const router = createRouter({
//     history: createWebHistory(process.env.BASE_URL),
   
//   })

// export default router   

const routes = [
    // router,
    
    // mode:'hash',
    // mode: 'history',
    // base: '/hot/', 
 
        {
            path: "/",
            redirect: "/Home",

        },
        {
            path: '/Home',
            name: "Home",
            component:
                Home

        },
        {
          
            path: "/listview",
            component: () => import(/* webpackChunkName: "about" */ '../views/Listvi'),
        },
        {
            name: "Searchpage",
            path: "/Searchpage",
            component: Searchpage
        },
        {
            name: "Login",
            path: "/login",
            component: Login
        },
        {
            name: "LoMin",
            path: "/loMin",
            component: LoMin,
            beforeEnter: (to, from, next) => {
                if (store.state.isLogin) {
                    next()
                } else {
                    if (from.name !== 'Login') {
                        next("/Login")

                    } else {
                      next()
                    }

                }

            }
        },
        {
            path: "/LoMe",
            component: () => import(/* webpackChunkName: "about" */ '../components/LoMe'),
            redirect:'/LoMe/UserMusic',
            children: [
                {
                    name: "About",
                    path: "About",
                    component: () => import(/* webpackChunkName: "about" */ '../components/About'),
                    beforeEnter: (to, from, next) => {

                        if (to.name == "About") {
                            console.log('dd')
                             store.state.isShow = false
                             next()
                        } else {
                            console.log('ww')
                            store.state.isShow = false
                            next()

                        }
                    }
                },
                {
                    name: "UserMusic",
                    path: "UserMusic",
                    component: () => import(/* webpackChunkName: "about" */ '../components/UserMusic'),
                    beforeEnter: (to, from, next) => {
                        if (to.name == "UserMusic") {
                             store.state.isShow = true
                             next()
                        } else {
                            console.log(store.state.isShow)
                            next()
                        }
                    }
                }
            ],
           
        },
     
        {
            name: "Sonelist",
            path: "/Sonelist",
            component: () => import(/* webpackChunkName: "about" */ '../components/Sonelist')
        }
 
   
]
const router = createRouter({
    history: createWebHashHistory(process.env.BASE_URL),
    routes
  })
export default router